﻿<!DOCTYPE html>
<!--承包商违章台账审批岗位设置-->
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>
    <link href="../static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="../static/js/vue-treeselect/vue-treeselect.js"></script>
    <!-- 行内编辑 css-->
    <style>
        .tb-edit .el-input {
            display: none
        }

        .tb-edit .current-row .el-input {
            display: block
        }

            .tb-edit .current-row .el-input + span {
                display: none
            }

        .tb-edit .el-select {
            display: none
        }

        .tb-edit .current-row .el-select {
            display: block
        }

            .tb-edit .current-row .el-select + span {
                display: none
            }

        .xian {
            display: block;
            text-align: center;
        }

        .yin {
            display: none;
            text-align: center;
        }

        .lineMust {
            position: absolute;
            right: 15px;
            bottom: 6px;
            bottom: 3px\0 !important;
            /* 兼容ie */
        }
    </style>
    <!-- 行内编辑 css-->
</head>
<body>
    <div id="app" v-cloak class="popupW50">
        <el-form ref="form" :inline="true" label-position="right" :model="formInline" class="demo-form-inline"
                 style="margin-bottom: 15px;">
            <el-row>
                <el-col class="head-tool">
                    <div class="new_title fl"><strong><img src="/static/images/icon1.png" />承包商违章审批岗位设置</strong></div>
                </el-col>
            </el-row>
            <el-row>
                <el-col :xs="8" :sm="8" :md="8" :lg="6" :xl="6">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-button type="primary" @click="add">添加审批岗位</el-button>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
        </el-form>
        <!--表格开始-->
        <el-table ref="table" stripe @current-change="tableHandleCurrentChange" class="tb-edit"
                  :data="ListItem.tableData" :row-key="getRowKeys" border
                  @selection-change="handleSelectionChange" row-style="height:10px" style="width: 100%;">
            <!-- 行内编辑 html-->


            <el-table-column prop="examineDuty" :label="ViolationNumber.ExamineDuty">
                <template scope="scope">
                        <el-select @visible-change="visibleChange" v-model="scope.row.examineDuty" slot="append" placeholder="请选择" size="mini">
                            <el-option label="请选择" value=""></el-option>
                            <el-option v-for="item in duties" :label="item.name" :value="item.id"></el-option>
                        </el-select>
                        <span>{{scope.row.examineDutyText}}</span>
                </template>
            </el-table-column>





            <el-table-column prop="dutyType" :label="ViolationNumber.DutyType">
                <template scope="scope">
                        <el-select @visible-change="visibleChange" v-model="scope.row.dutyType" slot="append" placeholder="请选择" size="mini">
                            <el-option label="请选择" value=""></el-option>
                            <el-option v-for="item in DutyType" :label="item.value" :value="item.key"></el-option>
                        </el-select>
                    <span>{{scope.row.dutyTypeText}}</span>
                </template>
            </el-table-column>
            <el-table-column width="90" prop="update" label="编辑">
                <template slot-scope="scope">
                    <span class="start xian">
                        <button type="button" class="elst-bt-xg"
                                @click=Edit('xg',scope.row.id,scope.$index)>
                            <i class="el-icon-edit"></i>
                        </button>
                    </span>
                    <span class="end yin">
                        <button type="button" class="elst-bt-xg " @click="Save(scope.$index, scope.row)">
                            <i class="el-icon-circle-check-outline"></i>
                            <!-- 保存 -->
                        </button>
                        <button type="button" class="elst-bt-xg " @click="Back(scope.$index, scope.row)">
                            <i class="el-icon-circle-close-outline"></i>
                            <!-- 撤销 -->
                        </button>
                    </span>
                </template>
            </el-table-column>
            <el-table-column width="90" label="操作" align="center">
                <template slot-scope="scope">
                    <button type="button" class="elst-bt-xg"
                            @click="deleteRow(scope.row.id,scope.$index)">
                        <i class="el-icon-delete"></i>
                    </button>
                </template>
            </el-table-column>
            <el-table-column prop="id" width="1" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                    <span>{{scope.row.id}}</span>
                </template>
            </el-table-column>
        </el-table>
    </div>
    <script type="text/javascript">
        //获取分页数据
        function GetPageData1(mythis, currentIndex, url) {
            var currObj = mythis;
            myAjax("post", mythis, url, { model: mythis.formInline.model, offset: 0, limit: 100 }, function (response) {
                console.log(response);
                if (response.data.pageData.length == 0) {
                    currObj.ListItem.tableData = [];
                    currObj.ListItem.total = 0;
                } else {
                    currObj.ListItem.tableData = response.data.pageData;
                    currObj.ListItem.total = response.data.pageData.length;
                }
            });

        }
        app = new Vue({
            el: '#app',
            data: function () {
                return {
                    ListItem: ListItem,
                    Type: [],
                    duties: [],
                    Form: {
                        id: guidEmpty,
                        examineDuty: '',
                        dutyType: '',
                    },
                    formInline: {
                        model: {
                            examineDuty: '',
                            dutyType: '',
                        },
                        offset: 0,
                        limit: 10
                    },
                    examineDutyTemp: '',
                    dutyTypeTemp: '',
                    delId: [],
                    tempId: guidEmpty
                }
            }, created: function () {
                var currApp = this;
                window.onresize = function () {
                    currApp.ListItem.tableHeight = window.innerHeight -
                        currApp.$refs.table.$el.offsetTop - 60;
                    if (currApp.ListItem.tableHeight < 112) {
                        currApp.ListItem.tableHeight = 112;
                    }
                }
            },
            mounted: function () {
                this.getSysDuty();
                this.DutyType = getDicData('SPGWLX');
                //初始化数据
                this.GetPageData(1);
                //列表高度自适应
                tablehigh(this);
            },

            created: function () {
                setTimeout(this.onSubmit, 100);
            },

            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //岗位集合
                getSysDuty: function () {
                    var mythis = this;
                    myAjax("post", this, '/api/SysDuty/GetList', { model: { Name: '', CreateFactory: null }, offset: 0, limit: 100 }, function (response) {
                        mythis.duties = menuHelper(response.data.pageData, guidEmpty)
                        //mythis.duties = response.data.pageData
                    }, false);
                },
                // 行内编辑 js
                add: function (formName) {
                    if ($('#tbody tr').attr("class") == "el-table__row current-row") {
                        showMessage(msg.EditingNotCompleted, 'error');
                    } else {
                        var newObj = {
                            examineDuty: '',//添加是清空录入数据的，每一项都要有
                            examineDutyText: '',
                            dutyType: '',
                            dutyTypeText: ''
                        }
                        $('.el-table__row').removeClass('current-row');
                        $('.el-table__row span.end').removeClass('xian');
                        $('.el-table__row span.end').addClass('yin');
                        $('.el-table__row span.start').removeClass('yin');
                        $('.el-table__row span.start').addClass('xian');
                        //this.ListItem.tableData.unshift(this.Form);
                        this.ListItem.tableData.unshift(newObj);
                        setTimeout(function () {
                            $('.el-table__row:eq(0)').addClass('current-row');
                            $('.el-table__row:eq(0) span.end').removeClass('yin');
                            $('.el-table__row:eq(0) span.end').addClass('xian');
                            $('.el-table__row:eq(0) span.start').removeClass('xian');
                            $('.el-table__row:eq(0) span.start').addClass('yin');
                        }, 100);
                    }
                },
                //修改
                Edit: function (val, id, index) {
                    var tlist = this.ListItem.tableData;
                    this.examineDutyTemp = tlist[index].examineDuty;
                    this.dutyTypeTemp = tlist[index].dutyType;
                    $('.el-table__row').removeClass('current-row');
                    $('.el-table__row:eq(' + index + ')').addClass('current-row');
                    $('.el-table__row span.end').removeClass('xian');
                    $('.el-table__row span.end').addClass('yin');
                    $('.el-table__row span.start').removeClass('yin');
                    $('.el-table__row span.start').addClass('xian');
                    $('.el-table__row:eq(' + index + ') span.end').removeClass('yin');
                    $('.el-table__row:eq(' + index + ') span.end').addClass('xian');
                    $('.el-table__row:eq(' + index + ') span.start').removeClass('xian');
                    $('.el-table__row:eq(' + index + ') span.start').addClass('yin');
                },
                // 保存
                Save: function (a, b) {
                    var mythis = this;
                    if (!b.examineDuty || !b.dutyType) {
                        showMessage(msg.NoMust, 'error');
                    } else {

                        var saveModel = mythis.ListItem.tableData[a];
                        myAjax("post", mythis, '/api/CBS_BreakRulesApproveDict/Save', saveModel, function (response) {

                        }, false);

                        b.examineDutyText = this.GetExamineDutyName(b.examineDuty)
                        b.dutyTypeText = this.GetDutyTypeName(b.dutyType);

                        $('.el-table__row').removeClass('current-row');
                        console.log("a", a);
                        console.log("b", b);
                        $('.el-table__row span.end').removeClass('xian');
                        $('.el-table__row span.end').addClass('yin');
                        $('.el-table__row span.start').removeClass('yin');
                        $('.el-table__row span.start').addClass('xian');
                    }
                },
                Back: function (a, b) {
                    if (this.examineDutyTemp != "" || this.dutyTypeTemp != "") {
                        b.examineDuty = this.examineDutyTemp;
                        b.dutyType = this.dutyTypeTemp;
                        this.examineDutyTemp = "";
                        this.dutyTypeTemp = "";
                        $('.el-table__row').removeClass('current-row');
                        $('.el-table__row span.end').removeClass('xian');
                        $('.el-table__row span.end').addClass('yin');
                        $('.el-table__row span.start').removeClass('yin');
                        $('.el-table__row span.start').addClass('xian');

                    } else {
                        $('.el-table__row').removeClass('current-row');
                        $('.el-table__row span.end').removeClass('xian');
                        $('.el-table__row span.end').addClass('yin');
                        $('.el-table__row span.start').removeClass('yin');
                        $('.el-table__row span.start').addClass('xian');
                        this.ListItem.tableData.splice(a, 1);
                    }
                },
                deleteRow: function (id, delrow) {
                    var mythis = this;
                    if (id == mythis.tempId || id == null || id == "") {
                        this.$confirm(' 是否确认继续?', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(function () {
                            var list = mythis.ListItem.tableData;
                            list.splice(delrow, 1);
                        }).catch(function () {
                            showMessage("已取消删除!");
                        });
                    } else {
                        this.$confirm(' 是否确认继续?', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(function () {
                            mythis.delId.push(id);
                            myAjax("post", mythis, '/api/CBS_BreakRulesApproveDict/DeleteMuti', mythis.delId, function (response) {
                                mythis.delId = [];
                                var list = mythis.ListItem.tableData;
                                list.splice(delrow, 1);
                            });
                        }).catch(function () {
                            showMessage("已取消删除!");
                        });
                    }
                },
                GetExamineDutyName: function (id) {
                    var duties = this.duties;
                    for (var i = 0; i < duties.length; i++) {
                        if (duties[i].id == id) {
                            return duties[i].name;
                        }
                    }
                    return id;
                },
                GetDutyTypeName: function (id) {
                    var DutyType = this.DutyType;
                    for (var i = 0; i < DutyType.length; i++) {
                        if (DutyType[i].key == id) {
                            return DutyType[i].value;
                        }
                    }
                    return id;
                },
                onSubmitForm: function (formName, obj) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        onSubmitForm(this, '/api/CBS_BreakRulesApproveDict/Save', obj);
                    });
                },
                handblur: function () {
                    //this.$refs.table.setCurrentRow(999);
                    //console.log("c", 'c');
                },
                //table选中行handle
                tableHandleCurrentChange: function (currentRow) {
                    //this.currSeelctId = currentRow.id;
                    //this.currSeelctCell = currentRow;
                },
                // 行内编辑 js

                indexMethod: function (index) {
                    return (this.ListItem.currentPage - 1) * this.ListItem.pagesize + index + 1;
                },

                handleNodeClick: function (data) {
                    console.log(data);
                },
                closeDialog: function () { closeDialog(this); },
                //删除方法
                onDelete: function () { onDelete(this, '/api/CBS_DayCheckItem/DeleteMuti'); },
                //列表选择触发
                handleSelectionChange: function (val) { handleSelectionChange(this, val); },
                //获取分页数据
                GetPageData: function (currentIndex) { GetPageData1(this, currentIndex, '/api/CBS_BreakRulesApproveDict/GetList') },
                //查询方法
                onSubmit: function () {
                    this.GetPageData(1);//onSubmit(this);
                },
                //pagesize改变 触发方法
                handleSizeChange: function (val) { handleSizeChange(this, val); },
                //跳页触发方法
                handleCurrentChange: function (val) { handleCurrentChange(this, val); },
            }
        });
        //下拉树数据格式化
        function menuHelper(list, pid) {
            var result = [];
            if (list.length <= 0)
                return list;
            list.forEach(function (v, i) {
                var temp = {};
                for (var key in v) {
                    temp[key] = v[key];
                }
                temp.label = v.name;
                temp.parentId = temp.parentId ? temp.parentId : guidEmpty;
                var obj;
                if (temp.parentId == pid) {
                    obj = temp;
                    var nextObj = menuHelper(list, temp.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;
        }
    </script>
</body>
</html>